package phan.connection;

import java.util.*;
import java.util.Date;
import  phan.connection.MySQLDBConnector;

public class ModifierMotDePassBean {

    private String pass;
    private String newpass1;
    private String newpass2;
    private String user;
   


    public ModifierMotDePassBean() {
        pass = "";
        newpass1 = "";
        newpass2 = "";
       user="";

        errors = new Hashtable();
    }

    public boolean validate() {
        boolean allOk = true;
        System.out.print("user la "+user);
         System.out.print("pass la "+pass);
          System.out.print("newpass1 la "+newpass1);
           System.out.print("newpass2 la "+newpass2);
        MySQLDBConnector con = new MySQLDBConnector();
          boolean check=   con.checkMotDePass(user,pass);
 System.out.print("check "+check);
        if (pass.equals("")) {
            getErrors().put("pass", "Veuillez entrer votre mot de pass!");
            pass="";
            allOk = false;
        }
          if (!pass.equals("")&&!check) {
            getErrors().put("pass", "Le mot de passe indiqué est incorrect.");
            pass="";
            allOk = false;
        }
           if (newpass1.equals("")) {
            errors.put("newpass1", "Entrer nouvel votre  mot de passe SVP !");
            newpass1 = "";
            allOk = false;
        }
        if (!newpass1.equals("")) {
            if ((newpass1.length() < 6 || newpass1.length() > 15)) {
                errors.put("newpass1", " nouvel votre mot de passe doit contenir entre 6 et 15 catactères !");
                newpass1 = "";
                allOk = false;
            }
           if (newpass2.equals("")&& !newpass1.equals("")) {
            errors.put("newpass2", "Entrer nouvel votre  mot de passe SVP !");
            newpass2 = "";
            allOk = false;
        }
            if (!newpass2.equals(newpass1)&&!newpass1.equals("")&&!newpass2.equals("")) {
            errors.put("newpass1", "Les mots de passe ne correspondent pas.");
            newpass2 = "";
            newpass1="";
            pass="";
            allOk = false;
        }
        }
       
System.out.print("allOk la "+allOk);
        return allOk;
    }
    private Hashtable errors;

    public String getErrorMsg(String s) {
        String errorMsg = (String) getErrors().get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }


    public Hashtable getErrors() {
        return errors;
    }

    /**
     * @param errors the errors to set
     */
    public void setErrors(Hashtable errors) {
        this.errors = errors;

    }

    /**
     * @return the pass
     */
    public String getPass() {
        return pass;
    }

    /**
     * @param pass the pass to set
     */
    public void setPass(String pass) {
        this.pass = pass;
    }

    /**
     * @return the newpass1
     */
    public String getNewpass1() {
        return newpass1;
    }

    /**
     * @param newpass1 the newpass1 to set
     */
    public void setNewpass1(String newpass1) {
        this.newpass1 = newpass1;
    }

    /**
     * @return the newpass2
     */
    public String getNewpass2() {
        return newpass2;
    }

    /**
     * @param newpass2 the newpass2 to set
     */
    public void setNewpass2(String newpass2) {
        this.newpass2 = newpass2;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @return the useremail
     */
    



}

